package is.billsharing.app;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class BillReportActivity extends Activity{
	 private static final String PREFS_NAME = "user";
	EditText billAmount,billDesc,billdate,billpaid,billshared;
    Button report_bill;
public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
    	 setContentView(R.layout.billreport);
    	   billAmount = (EditText)findViewById(R.id.bill_amt);
           billDesc = (EditText)findViewById(R.id.billdesc);
   
           billdate = (EditText)findViewById(R.id.bill_date);
           billpaid=(EditText)findViewById(R.id.paidid);
           billshared=(EditText)findViewById(R.id.sharedids);
           report_bill=(Button)findViewById(R.id.report_bill);
           SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
           final int uid = settings.getInt("uid",0);
           report_bill.setOnClickListener(new View.OnClickListener() 
	        {
	            public void onClick(View v) 
	            {
           ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
   		postParameters.add(new BasicNameValuePair("uid",""+ uid+""));
   		postParameters.add(new BasicNameValuePair("billamt", billAmount.getText().toString()));
   		postParameters.add(new BasicNameValuePair("billdesc", billDesc.getText().toString()));
   		postParameters.add(new BasicNameValuePair("billdate", billdate.getText().toString()));
   		postParameters.add(new BasicNameValuePair("paidid", billpaid.getText().toString()));
   		postParameters.add(new BasicNameValuePair("sharedids", billshared.getText().toString()));
   		
           String response;
        
   		try
           {
           	response = CustomHttpClient.executeHttpPost("BillReport", postParameters);
           	String res=response.toString();
    	    res= res.replaceAll("\\s+","");
    	    if(res.equals("true"))
    	    {
    	    	Intent intent=new Intent(BillReportActivity.this,TabsampleActivity.class);
    	    	
    	    	startActivity(intent);
    	    }
    	    
    	    else
    	    {
    	    	Intent intent=new Intent(BillReportActivity.this,BillActivity.class);
    	    	
    	    	startActivity(intent);
    	    }
           	
           	}
           	
           
   		catch(Exception e)
   		{
   			e.printStackTrace();
   		}
	            }
	        });
}
}